// ignore_for_file: non_constant_identifier_names

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

 import '/utils/ScreenFit.dart';

QGScaffold(
    {title,
    body,
    drawer,
    navColor = Colors.white,
    foregroundColor = Colors.black,
    bgColor = Colors.white,
    leading,
    actions,
    key}) {
  return Scaffold(
    key: key,
    appBar: AppBar(
      centerTitle: true,
      foregroundColor: Color(0xFFffffff),
      shadowColor: Colors.transparent,
      backgroundColor: Color(0xFF0B2C2C),
      title: Text(title,
          style: TextStyle(
            fontSize: 15.rpx,
            color: Color(0xFFffffff),
            fontWeight: FontWeight.bold,
          )),
      leading: leading,
      actions: actions,
    ),
    backgroundColor: bgColor,
    body: body,
  );
}

QGImage(
    {String? url,
    String? asset,
    width,
    height,
    fit = BoxFit.cover,
    color,
    borderRadius}) {
      // return Image.asset('images/about_logo.png',
      //   fit: fit, width: width, height: height, color: color,alignment: Alignment.center,);

  if (asset != null) {
    String name = asset;
    if (!name.endsWith(".png") &&
        !name.endsWith(".jpg") &&
        !name.endsWith(".jpeg") &&
        !name.endsWith(".gif")) {
      name = "$name.png";
    }
    if (!name.startsWith("images/")) {
      name = "images/$name";
    }
    return Image.asset(name,
        fit: fit, width: width, height: height, color: color,alignment: Alignment.center,);
  } 

  if (url == null || url.isEmpty) {
    return Container(width: width, height: height, color: color);
  }

  final imageWidget = CachedNetworkImage(
    imageUrl: url,
    width: width,
    height: height,
    fit: fit,
    color: color,
    colorBlendMode: BlendMode.color,
    placeholder: (context, url) => Image.asset("images/about_logo.png" ,width: width,height: height,fit: fit,alignment: Alignment.center,),
    errorWidget: (context, url, error) => Image.asset("images/about_logo.png",width: width,height: height,fit: fit,alignment: Alignment.center,),
  );

  if (borderRadius != null && borderRadius > 0) { 
    ClipRRect(
      borderRadius: BorderRadius.circular(borderRadius),
      child: imageWidget,
    );
  }

  return imageWidget;
}


// QGImage(
//     {String? url,
//     String? asset,
//     width,
//     height,
//     fit = BoxFit.cover,
//     color,
//     borderRadius}) {
//   if (asset != null) {
//     String name = asset;
//     if (!name.endsWith(".png") &&
//         !name.endsWith(".jpg") &&
//         !name.endsWith(".jpeg") &&
//         !name.endsWith(".gif")) {
//       name = "$name.png";
//     }
//     if (!name.startsWith("images/")) {
//       name = "images/$name";
//     }
//     return Image.asset(name,
//         fit: fit, width: width, height: height, color: color,
//         frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
//           if (wasSynchronouslyLoaded || frame != null) {
//             return child; // 图片已加载完成
//           }
//           return SizedBox(width: 10,);
//         },
//         errorBuilder: (context, error, stackTrace) {
//           return const Icon(Icons.error); // 错误占位
//         },
//       );
//   }

//   if (url == null || url.isEmpty) {
//     return Container(width: width, height: height, color: color);
//   }


// //  imageWidget(){
// //     return Image.asset("images/about_logo.png");
// // };

//   final imageWidget = CachedNetworkImage(
//     imageUrl: url,
//     width: width,
//     height: height,
//     fit: fit,
//     color: color,
//     colorBlendMode: BlendMode.color,
//     placeholder: (context, url) => const Center(
//         child:
//             CircularProgressIndicator(strokeWidth: 0.3, color: Colors.black)),
//     errorWidget: (context, url, error) => Image.asset("images/about_logo.png"),
//   );

 
//   if (borderRadius != null && borderRadius > 0) {
//     ClipRRect(
//       borderRadius: BorderRadius.circular(borderRadius),
//       child: Image.network(url,width:width,height: height,fit: fit,
//       //  frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
//       //     if (wasSynchronouslyLoaded || frame != null) {
//       //       return child; // 图片已加载完成
//       //     }
//       //     return Container();
//       //   },
//         errorBuilder: (context, error, stackTrace) {
//           return const Icon(Icons.error); // 错误占位
//         },
//       ),
//     );
//   }

//   return Image.network(url,width:width,height: height,fit: fit,
//       // frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
//       //   if (wasSynchronouslyLoaded || frame != null) {
//       //     return child; // 图片已加载完成
//       //   }
//       //   return Container();
//       // },
//       errorBuilder: (context, error, stackTrace) {
//         return const Icon(Icons.error); // 错误占位
//       },
//   );
// }
